<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<%@ include file="/web/header.jsp"%>
<title>Insert title here</title>
</head>
<body>
    <form id="form" class="layui-form layui-form-pane" method="post">
    	<input type="hidden" name="id" value="${department.id}"/>
        <div class="layui-form-item">
            <label class="layui-form-label">编号</label>
            <div class="layui-input-block">
                <input type="text" name="code" value="${department.code}" lay-verify="required" autocomplete="off"
                	placeholder="请输入编号" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name"  value="${department.name}"  lay-verify="required" autocomplete="off"
                	placeholder="请输入名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">电话</label>
            <div class="layui-input-block">
                <input type="text" name="tel"  value="${department.tel}"  placeholder="请输入密码"   autocomplete="off"
                    class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <div class="layui-input-block">
                <input type="button" class="layui-btn" onclick="submitForm()" value="确定" />
                <input type="button" class="layui-btn" onclick="closeThis()" value="取消" />
            </div>
        </div>
    </form>
    
    <script type="text/javascript">
	    function submitForm() {
			$.post(
				"${path}/department?method=update",
				$("#form").serialize(), // 自动把表单的数据序列化为json格式数据
				function(jsonResult) {
					console.log(jsonResult);
					if(jsonResult.success) {
						mylayer.successMsg(jsonResult.msg);
						//当你在iframe页面关闭自身时获得当前弹出框的index索引
						var index = parent.layer.getFrameIndex(window.name);
						// js一个方法，定时器，1000毫秒之后自动执行function里面的代码
						setTimeout(function() {
							 // 关闭弹出层
							 parent.layer.close(index); 
							 // 刷新父页面
							 window.parent.location.reload();
						}, 1000);
					} else {
						mylayer.errorMsg(jsonResult.msg);
					}
				},
				"json"
			);
		}
    </script>
</body>
</html>